package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.StrategyComment;
import cn.wolfcode.trip.base.query.StrategyCommentQueryObject;
import cn.wolfcode.trip.base.service.IStrategyCommentService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Copyright: Copyright (c) 2019 Super520
 * 描述：
 *
 * @package: cn.wolfcode.trip.admin.controller
 * @author: Patch
 * @date: 2019/5/28 0:04
 * 总结:
 */
@Controller
@RequestMapping("strategyComment")
public class StrategyCommentController {
    @Autowired
    private IStrategyCommentService commentService;

    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo") StrategyCommentQueryObject qo) {
        qo.setOrderBy("sc.createTime desc");
        model.addAttribute("pageInfo", commentService.query(qo));
        return "strategyComment/list";
    }

    /**
     * 更新发布状态
     *
     * @param comment
     */
    @RequestMapping("updateState")
    @ResponseBody
    public Object updateState(StrategyComment comment) {
        JsonResult result = new JsonResult();
        try {
            commentService.updateState(comment);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("亲，操作失败");
        }
        return result;
    }
}
